# -*- coding: utf-8 -*-
# @Time    : 2019/10/17 18:42
# @Author  : LiHaowen
# @Email   : lihaowen2017@163.com
# @File    : property_test.py
from datetime import date, datetime


class User:
    def __init__(self, name, birthday):
        self.name = name
        self.birthday = birthday
        self._age = 0

    # def get_age(self):
    #     return datetime.now().year - self.birthday.year

    @property  # 计算属性 ,将函数变为属性描述符
    def age(self):  # 用处:可以放入时区转换逻辑
        return datetime.now().year - self.birthday.year

    @age.setter  # 将函数以属性赋值的方式进行赋值
    def age(self, value):
        self._age = value


if __name__ == '__main__':
    user = User("b1", date(year=1987, month=1, day=1))
    user.age = 30
    print(user._age)  # 30
    print(user.age)  # 32
